我的情况
我创建了一个搜索功能,为此我创建了一个新的索引器和搜索器。问题是当我输入一个带有空格的搜索查询时。下面的例子。
数据
我已经创建了这些人并站在我的索引中:
+---------------+------------+-------------+
| Person number | First name | Last name |
+---------------+------------+-------------+
| 1 | Ilse | Van de Burg |
| 2 | Devolder | Marlijn |
+---------------+------------+-------------+
搜索结果
我尝试了下一个查询:
+--------------+------------------+----------------+------------------+
| Query number | Term | Actual result* | Accepted result* |
+--------------+------------------+----------------+------------------+
| 1 | van | 1 | 1 |
| 2 | van de | 1 | 1 |
| 3 | ilse | 1 | 1 |
| 4 | van de burg | | 1 |
| 5 | van de burg ilse | | 1 |
| 6 | de | 1 & 2 | 1 & 2 |
| 7 | devolder | 2 | 2 |
| 8 | devolder marlijn | | 2 |
| 9 | marijn devolder | | 2 |
+--------------+------------------+----------------+------------------+
* number of the person. if empty: nothing found or accepted
问题
有些查询不是我接受的。我怎么能解决这个问题?
我的代码
这是我制作的代码:
BaseSearchProvider searcher = ExamineManager.Instance.SearchProviderCollection["PersonSearcher"];
ISearchCriteria searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
ISearchCriteria query = searchCriteria.Field("lastname", term.MultipleCharacterWildcard()).Or()
.Field("firstname", term.MultipleCharacterWildcard()).Or()
.OrderBy("lastname", "firstname").Compile();
return searcher.Search(query);
配置更新 1
检查索引
<IndexSet SetName="Artsen" IndexPath="~/App_Data/TEMP/ExamineIndexes/Artsen/">
<IndexAttributeFields>
<add Name="id" Type="int" />
<add Name="nodeName" />
<add Name="nodeTypeAlias" />
</IndexAttributeFields>
<IndexUserFields>
<add Name="email" />
<add Name="fax" />
<add Name="naam" EnableSorting="true" />
<add Name="onderzoeken" Type="int[]" />
<add Name="specialismen" Type="int[]" />
<add Name="subspecialismen" Type="int[]" />
<add Name="telefoon" />
<add Name="titel" EnableSorting="true" />
<add Name="voornaam" EnableSorting="true" />
<add Name="website" />
</IndexUserFields>
<IncludeNodeTypes>
<add Name="arts" />
</IncludeNodeTypes>
</IndexSet>
检查设置(检查索引提供程序):
<add name="ArtsenIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine" supportUnpublished="false"
supportProtected="true" indexSet="Artsen"
analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
检查设置(检查搜索提供程序):
<add name="ArtsenSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" supportUnpublished="false"
supportProtected="false" indexSet="Artsen" enableLeadingWildcard="true"
analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
也试过更新2
我也试过这个并得到了最好的结果:
query = searchCriteria.GroupedOr(new List<string>() { "naam" }, term.MultipleCharacterWildcard(), term.Escape()).Or()
.GroupedOr(new List<string>() { "voornaam" }, term.MultipleCharacterWildcard(), term.Escape()).Or()
.GroupedOr(new List<string>() { "titel" }, term.MultipleCharacterWildcard(), term.Escape()).Or()
.OrderBy("naam", "voornaam").Compile();
当我在上面ToString()
进行searchCriteria
查询并搜索时van de burg
,它给了我这个:
{ SearchIndexType: , LuceneQuery: (naam:van de burg* (naam:van de burg)) (voornaam:van de burg* (voornaam:van de burg)) (titel:van de burg* (titel:van de burg)) }
这里的问题是当我得到两个姓氏相同的人时。例如:
+---------------+------------+-----------+
| Person number | First name | Last name |
+---------------+------------+-----------+
| 3 | Marc | De Vadder |
| 4 | Freddy | De vadder |
+---------------+------------+-----------+
搜索结果:
结果 1 到 9 都很好。
+--------------+------------------+----------------+------------------+
| Query number | Term | Actual result* | Accepted result* |
+--------------+------------------+----------------+------------------+
| 10 | de vadder | 3 & 4 | 3 & 4 |
| 11 | de vadder freddy | 3 & 4 | 4 |
| 11 | de vadder marc | 3 & 4 | 3 |
+--------------+------------------+----------------+------------------+
* number of the person. if empty: nothing found or accepted