lucene - Search by exact words in a phrase using Umbraco Examine -


i have description field per content , are:

for content1:

the quick brown fox jumps on lazy dog. , lazy dog good.

 

for content2:

the lazy fog crazy.

now, when use keyword = lazy dog, want give result content1 , not content2

i tried like:

basesearchprovider searcher = examinemanager.instance.searchprovidercollection["mysearch"]; isearchcriteria criteria =             searcher.createsearchcriteria()                .groupedand( new list<string> { "description" }, "lazy dog") )                .compile();  isearchresults result = searcher.search( criteria ); 

but didn't gave me desired results, give me results: content1 , content2.

what should in order content1 result ?

by default examine compiling query to:

+(+description:lazy dog) 

and based on it's returning results both: lazy , dog words.

what want achieve is:

+(+description:"lazy dog") 

first of need try escape phrase. in case be:

basesearchprovider searcher = examinemanager.instance.searchprovidercollection["mysearch"]; isearchcriteria criteria =             searcher.createsearchcriteria()                .groupedand( new list<string> { "description" }, "lazy dog".escape()) )                .compile();  isearchresults result = searcher.search( criteria ); 

can't test now, there problems in past remember. second option , life saver you, may building search query manually , using raw query.

basesearchprovider searcher = examinemanager.instance.searchprovidercollection["mysearch"]; isearchcriteria criteria = searcher.createsearchcriteria();  var query = criteria.rawquery("+description:\"lazy dog\"");  isearchresults result = searcher.search( query ); 

and should return correct = matched result only. personally, i've used boosting of specific words point results higher in score list, if want have matched items, try above solutions , let me know if helped you.

if want deal more 1 property, can either use fluent api methods groupedand or groupedor (depending of desired behaviour of search) or build more advanced raw query.

for first option, check grouped operations documentation: https://github.com/shazwazza/examine/wiki/grouped-operations.

for second scenario best analyze how it's done e.g. in ezsearch package (which btw. awesome!): https://github.com/umco/umbraco-ezsearch/blob/master/src/our.umbraco.ezsearch/web/ui/views/macropartials/ezsearch.cshtml.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -