本文介绍了如何使用vb.net在lucene索引中进行整数搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在lucene索引中使用以下代码进行搜索加入no但是它给我一个空结果你可以帮我在lucene索引中进行整数搜索 私人 Sub btnShowResult_Click(发件人作为 对象,e As RoutedEventArgs) 尝试 Dim dt_Result As 新 DataTable Dim FinalTable As 新 DataTable Dim strTagSbFld As 字符串 strTagSbFld = GetTagSbFldSQL() Dim searchString As String = txtSearch.Text Dim query1 As String =(strTagSbFld) ' MsgBox(query1) conn.Open() adap.SelectCommand = 新 SqlCommand(query1,conn) adap.Fill(dt_Result) Dim Field0,Field1,Field2,Field3,Field4,Field5 As String Field0 = dt_Result.Columns( 0 )。标题 Field1 = dt_Result.Columns( 1 )。标题 Field2 = dt_Result.Columns( 2 )。标题 Field3 = dt _Result.Columns( 3 )。标题 Field4 = dt_Result.Columns( 4 )。标题 Field5 = dt_Result.Columns( 5 )。标题 ' 指定索引文件的存储位置 Dim indexFileLocation 作为 字符串 = C:\ Users \Shahrukh \Documents\Visual Studio 2012 \Projects \Simple search1 \Simple search1 \New folder Dim dir As Lucene.Net.Store.Directory = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation) ' 指定se arch字段,lucene在多个字段中搜索 Dim searchfields As 字符串()= 新 字符串(){Field0, Field1,Field2,Field3,Field4,Field5} Dim indexSearcher As 新 IndexSearcher(dir) ' 制作布尔值查询搜索并获取搜索到的点击数 ' Dim hits = indexSearcher.Search(QueryMaker( searchString,searchfields)) ElseIf SearchCriteria = AccessionNo 然后 ' MsgBox(strTagSbFld) Dim Searchresults As 新列表( SearchResultsAccessionNo)() Dim hits = indexSearcher.Search(QueryMaker(searchString,searchfields)) 对于 i 作为 整数 = 0 hits.Length() - 1 Dim 结果作为 新 SearchResultsAccessionNo() result.SrNo = i + 1 result.Title = hits.Doc(i).Ge tField(Field0).StringValue() result.AccessionNo = hits.Doc(i).GetField(Field1).StringValue() result.AccessionNo = hits.Doc(i).GetField(Field2) .StringValue() result.Location = hits.Doc(i).GetField(Field3).StringValue() result.CallNo = hits.Doc(i).GetField(Field4).StringValue() result.Status = hits.Doc(i).GetField(Field5).StringValue() Searchresults.Add(result) Next indexSearcher.Close() ' adap.Fill(Searchresults) dGridResults.ItemsSource = Searchresults 解决方案 我的解决方案:你没有。 自从Lucene索引是关于索引文本的,我猜你需要在搜索之前将整数转换为文本/ BLOCKQUOTE> I am using below code for search accession no in lucene index but its give me an empty result can you please help me to do integer search in lucene indexPrivate Sub btnShowResult_Click(sender As Object, e As RoutedEventArgs) Try Dim dt_Result As New DataTable Dim FinalTable As New DataTable Dim strTagSbFld As String strTagSbFld = GetTagSbFldSQL() Dim searchString As String = txtSearch.Text Dim query1 As String = (strTagSbFld) 'MsgBox(query1) conn.Open() adap.SelectCommand = New SqlCommand(query1, conn) adap.Fill(dt_Result) Dim Field0, Field1, Field2, Field3, Field4, Field5 As String Field0 = dt_Result.Columns(0).Caption Field1 = dt_Result.Columns(1).Caption Field2 = dt_Result.Columns(2).Caption Field3 = dt_Result.Columns(3).Caption Field4 = dt_Result.Columns(4).Caption Field5 = dt_Result.Columns(5).Caption ' Specify the location where the index files are stored Dim indexFileLocation As String = "C:\Users\Shahrukh\Documents\Visual Studio 2012\Projects\Simple search1\Simple search1\New folder" Dim dir As Lucene.Net.Store.Directory = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation) ' specify the search fields, lucene search in multiple fields Dim searchfields As String() = New String() {Field0, Field1, Field2, Field3, Field4, Field5} Dim indexSearcher As New IndexSearcher(dir) ' Making a boolean query for searching and get the searched hits 'Dim hits = indexSearcher.Search(QueryMaker(searchString, searchfields)) ElseIf SearchCriteria = "AccessionNo" Then 'MsgBox(strTagSbFld) Dim Searchresults As New List(Of SearchResultsAccessionNo)() Dim hits = indexSearcher.Search(QueryMaker(searchString, searchfields)) For i As Integer = 0 To hits.Length() - 1 Dim result As New SearchResultsAccessionNo() result.SrNo = i + 1 result.Title = hits.Doc(i).GetField(Field0).StringValue() result.AccessionNo = hits.Doc(i).GetField(Field1).StringValue() result.AccessionNo = hits.Doc(i).GetField(Field2).StringValue() result.Location = hits.Doc(i).GetField(Field3).StringValue() result.CallNo = hits.Doc(i).GetField(Field4).StringValue() result.Status = hits.Doc(i).GetField(Field5).StringValue() Searchresults.Add(result) Next indexSearcher.Close() 'adap.Fill(Searchresults) dGridResults.ItemsSource = Searchresults 解决方案 My solution: you don't.Since Lucene index is about indexing text, I guess you need to convert your integer to text before doing search. 这篇关于如何使用vb.net在lucene索引中进行整数搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 11:06