简体   繁体   中英

advanced search with solr and haystack?

Say you have a query:

(apples OR oranges) AND fresh location:cityGoesHere

By default haystack uses the auto_query in which data gets auto-escaped so a search would be logged as:

INFO: [collection1] webapp=/solr path=/select/ params={spellcheck=true&facet=on&fl=*+score&start=0&q=(\(apples+or+oranges\)+and+fresh+location\:cityGoesHere)&spellcheck.count=1&...

Of course, Solr will treat the "(", ")" and ":" chars as literals so no grouping will be made and the whole text will be searched against the default field and the location field will be ignored

Is there any method to achieve advanced solr searches through haystack, aside from parsing the query and assign different pieces from it to AutoQuery, Raw, Exact input types, as one sees fit, then chaining the SearchQuerySets together?

I ended up creating my own input mostly using Raw haystack inputs.

The only downfall is that this input is using Solr specific syntax, so it cannot be used with other search backends.


Later edit:

AltParser can also be used in combination with Extended Dismax parser. Works like butter!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM