Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Hein 29 posts 158 karma points
    Oct 03, 2017 @ 13:07
    Hein
    0

    Search doesn't work when I use spaces.

    My situation

    I've created a search function and for this I created a new indexer and searcher for that. The problem is when I enter a search query with a white space in it. Example below.

    Data

    I've got this persons created and stands inside my index:

    +---------------+------------+-------------+
    | Person number | First name | Last name   |
    +---------------+------------+-------------+
    | 1             | Ilse       | Van de Burg |
    | 2             | Devolder   | Marlijn     |
    +---------------+------------+-------------+
    

    Search results

    I've tried next queries:

    +--------------+------------------+----------------+------------------+
    | 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
    

    Question

    Some queries are not what I accepted. How could I solve this?

    My code

    Here is my code I've made:

    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);
    

    Configurations update

    Examine index

    <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>
    

    Examine settings (examine index provider):

    <add name="ArtsenIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine" supportUnpublished="false"
         supportProtected="true" indexSet="Artsen"
         analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
    

    Examine settings (examine search provider):

    <add name="ArtsenSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" supportUnpublished="false"
         supportProtected="false" indexSet="Artsen" enableLeadingWildcard="true"
         analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
    

    Tried also

    I've also tried this and got the best results:

    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();
    

    The problem here is when I get two persons with the same last name. For example:

    +---------------+------------+-----------+
    | Person number | First name | Last name |
    +---------------+------------+-----------+
    | 3             | Marc       | De Vadder |
    | 4             | Freddy     | De vadder |
    +---------------+------------+-----------+
    

    Search results:

    +--------------+------------------+----------------+------------------+
    | 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
    
  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Oct 03, 2017 @ 16:28
    Ismail Mayat
    0

    hein,

    Can you write out searchCriteria.ToString() and paste back the result. This will give you the generated lucene query.

    Regards

    Ismail

  • Hein 29 posts 158 karma points
    Oct 04, 2017 @ 06:24
    Hein
    0

    searchCriteria.ToString() gives me this:

    { 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)) }
    

    P.S.: Uses the last query of my question and search term van de burg.

Please Sign in or register to post replies

Write your reply to:

Draft