dotJEM / json-index

MIT License
7 stars 3 forks source link

Query vs JObject Search strategy problem #11

Open paratoner opened 8 years ago

paratoner commented 8 years ago

Hi again, When i use ISearchResult Search(JObject query, string contentType = "") method index configuration Field Strategy is : DotJEM.Json.Index.Configuration.FieldStrategies.FieldStrategy but when i use ISearchResult Search(Query query) method the Field Strategy is :

DotJEM.Json.Index.Configuration.FieldStrategies.TermFieldStrategy

can you explain why this reason? Because it occur problem for me. For example :

var query = JObject.Parse("{\"Name\":\"Lill\"}");
 List <dynamic> result = index.Searcher.Search(query).Select(hit => hit.Json).ToList();

it returns result. but i have not a person that named "Lill". it is name is Lilly. this method adds wildcardquery due to the FieldStrategy

  public virtual Query BuildQuery(string field, string value)
        {
            value = value.ToLowerInvariant();
            string[] words = value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
            if (!words.Any())
                return null;

            BooleanQuery query = new BooleanQuery();
            foreach (string word in words)
            {
                //Note: As for the WildcardQuery, we only add the wildcard to the end for performance reasons.
                query.Add(new FuzzyQuery(new Term(field, word)), Occur.SHOULD);
                query.Add(new WildcardQuery(new Term(field, word + "*")), Occur.SHOULD);
            }
            return query;
        }

but when i use

Query query = new TermQuery(new Term("Name", @"Lill"));
List <dynamic> result = index.Searcher.Search(query).Select(hit => hit.Json).ToList();

it returns 0 result and it is correct.

i dont want to change your source code . So can you give me a trick for this problem? sorry about my english. Thanks.

jeme commented 8 years ago

It's not a good explanation, but the reason is mainly that we abandoned the idea of having a Search method that takes a JObject in favor for the regular ones.

The logic was that you could construct a search in a similar language as what your documents was written in, but in the end it was far more simple to use index.Search(string query).

This has left a big chunk of the framework in a bit of a limbo.

Instead of changing the code, you can replace services.

You can use:

var index = new LuceneStorageIndex(factory: new MyCustomServiceFactory());

class MyCustomServiceFactory : DefaultServiceFactory {
  public override ILuceneSearcher CreateSearcher(IStorageIndex index) {
    return new LuceneSearcher(index, new MyQueryBuilder());
  }
}

But these are services that is very much in flux at this time :(

The idea of allowing services to be replaced will remain though.