Custom search in own SearchComponent
Hi there, I’m working on a custom SearchComponent to add some docs to the response with another filter query than in the original request. Here is what I currently have: public void process(ResponseBuilder rb) throws IOException { if(rb.getResults() != null) { QueryParser queryParser = new QueryParser("name", new StandardAnalyzer()); Query query = null; try { query = queryParser.parse("text_tg:" + rb.getQueryString()); } catch (ParseException e) { e.printStackTrace(); } TopDocs additionalDocs = rb.req.getSearcher().search(query, 5); ScoreDoc[] scoreDocs = additionalDocs.scoreDocs; System.out.println(additionalDocs.scoreDocs.length); ArrayList specialDocs = new ArrayList(); for(int i = 0; i < scoreDocs.length; i++) { Document doc = rb.req.getSearcher().doc(scoreDocs[i].doc); specialDocs.add(doc); } rb.rsp.add("special_responses", specialDocs); } } This works fine but doesn’t filter the results. As soon as I add something like ‘ AND product_type:106’ in the query, use getDocList(Query query, Query filter, Sort lsort, int offset, int len) or a BooleanQuery a la: Query query = null; Query filterQuery = null; try { filterQuery = queryParser.parse("product_type:106"); query = queryParser.parse("text_tg:" + rb.getQueryString()); } catch (ParseException e) { e.printStackTrace(); } BooleanClause queryClause = new BooleanClause(query, BooleanClause.Occur.SHOULD); BooleanClause filterClause = new BooleanClause(filterQuery, BooleanClause.Occur.FILTER); BooleanQuery.Builder builder = new BooleanQuery.Builder(); builder.add(queryClause); builder.add(filterClause); BooleanQuery bQuery = builder.build(); TopDocs additionalDocs = rb.req.getSearcher().search(bQuery, 5); I get 0 results. Does anyone know what I am doing wrong? Thanks in advance and best regards, Moritz Schmidt Spektrum Kompakt - Themen auf den Punkt gebracht. www.spektrum.de/kompakt <http://www.spektrum.de/kompakt> Spektrum der Wissenschaft Verlagsgesellschaft mbH Sitz Heidelberg Registergericht Mannheim, HRB 338114 Geschaeftsfuehrer: Markus Bossle Spektrum der Wissenschaft was founded in 1978 as the German edition of Scientific American. It publishes several popular science magazines in print and digital and operates the biggest German language website on science news. Spektrum der Wissenschaft is part of SpringerNature.
Re: Custom search in own SearchComponent
Using QParser solved the problem. Many thanks, best regards and a nice start in the week, -- Moritz Schmidt Am 01.03.19, 11:25 schrieb "Mikhail Khludnev" : Just a guess QueryParser might be a Lucene class, which isn;t aware of Solr scheme and hence might not properly convert term to number or point "product_type:106" Check the particular query with Solr fq, then use QParser for parsing. See QueryComponent as a sample. On Fri, Mar 1, 2019 at 12:59 PM Moritz Schmidt wrote: > Hi there, > > I’m working on a custom SearchComponent to add some docs to the response > with another filter query than in the original request. > Here is what I currently have: > > public void process(ResponseBuilder rb) throws IOException { > if(rb.getResults() != null) { > QueryParser queryParser = new QueryParser("name", new > StandardAnalyzer()); > Query query = null; > try { > query = queryParser.parse("text_tg:" + rb.getQueryString()); > } catch (ParseException e) { > e.printStackTrace(); > } > > TopDocs additionalDocs = rb.req.getSearcher().search(query, 5); > ScoreDoc[] scoreDocs = additionalDocs.scoreDocs; > System.out.println(additionalDocs.scoreDocs.length); > ArrayList specialDocs = new ArrayList(); > > for(int i = 0; i < scoreDocs.length; i++) { > Document doc = rb.req.getSearcher().doc(scoreDocs[i].doc); > specialDocs.add(doc); > } > > rb.rsp.add("special_responses", specialDocs); > } > } > > This works fine but doesn’t filter the results. > As soon as I add something like ‘ AND product_type:106’ in the query, use > getDocList(Query query, Query filter, Sort lsort, int offset, int len) or a > BooleanQuery a la: > Query query = null; > Query filterQuery = null; > try { > filterQuery = queryParser.parse("product_type:106"); > query = queryParser.parse("text_tg:" + rb.getQueryString()); > } catch (ParseException e) { > e.printStackTrace(); > } > > BooleanClause queryClause = new BooleanClause(query, > BooleanClause.Occur.SHOULD); > BooleanClause filterClause = new BooleanClause(filterQuery, > BooleanClause.Occur.FILTER); > > BooleanQuery.Builder builder = new BooleanQuery.Builder(); > builder.add(queryClause); > builder.add(filterClause); > BooleanQuery bQuery = builder.build(); > > TopDocs additionalDocs = rb.req.getSearcher().search(bQuery, 5); > > I get 0 results. > > Does anyone know what I am doing wrong? > > Thanks in advance and best regards, > > Moritz Schmidt > > Spektrum Kompakt - Themen auf den Punkt gebracht. > www.spektrum.de/kompakt <http://www.spektrum.de/kompakt> > > > Spektrum der Wissenschaft Verlagsgesellschaft mbH > Sitz Heidelberg > Registergericht Mannheim, HRB 338114 > Geschaeftsfuehrer: Markus Bossle > > > Spektrum der Wissenschaft was founded in 1978 as the German edition of > Scientific American. > It publishes several popular science magazines in print and digital and > operates the biggest German language website on science news. > Spektrum der Wissenschaft is part of SpringerNature. > -- Sincerely yours Mikhail Khludnev Spektrum Kompakt - Themen auf den Punkt gebracht. www.spektrum.de/kompakt <http://www.spektrum.de/kompakt> Spektrum der Wissenschaft Verlagsgesellschaft mbH Sitz Heidelberg Registergericht Mannheim, HRB 338114 Geschaeftsfuehrer: Markus Bossle Spektrum der Wissenschaft was founded in 1978 as the German edition of Scientific American. It publishes several popular science magazines in print and digital and operates the biggest German language website on science news. Spektrum der Wissenschaft is part of SpringerNature.
Suggester case (in)sensitive
Hello everyone. I’m trying to build autocomplete functionality. My setup works but has one problem: When using HighFrequencyDictionaryFactory the Suggestion-Results I get are all lowercase as defined in my schema.xml: Without the LowerCaseFilterFactory I get my results as I want but the search is case sensitive. When using DocumentDictionaryFactory I get my suggestions in unaltered form but I get a lot of duplicates as I’m using amongst others a field for keywords for suggestions and DocumentDictionaryFactory saves them per Document(?) Is this intended behaviour for HighFrequencyDictionaryFactory? In case it is, how would you solve that? Remove the LowerCaseFilterFactory and write a custom SuggestComponent that searches the query lowercased and with the first letter capitalized? Here’s the solrconfig.xml excerpt for reference: texts AnalyzingInfixLookupFactory HighFrequencyDictionaryFactory suggestion suggestion_text false true true false 0.0 Thanks for your help, Moe
Re: Suggester case (in)sensitive
Does anyone have an idea? Thanks and best regards, Moe > Am 20.03.2019 um 15:19 schrieb Moritz Schmidt : > > Hello everyone. > > I’m trying to build autocomplete functionality. > My setup works but has one problem: > When using HighFrequencyDictionaryFactory the Suggestion-Results I get are > all lowercase as defined in my schema.xml: > > positionIncrementGap="100" multiValued="true" stored="true"> > > > > > > > Without the LowerCaseFilterFactory I get my results as I want but the search > is case sensitive. > > When using DocumentDictionaryFactory I get my suggestions in unaltered form > but I get a lot of duplicates as I’m using amongst others a field for > keywords for suggestions and DocumentDictionaryFactory saves them per > Document(?) > > > Is this intended behaviour for HighFrequencyDictionaryFactory? > In case it is, how would you solve that? Remove the LowerCaseFilterFactory > and write a custom SuggestComponent that searches the query lowercased and > with the first letter capitalized? > > Here’s the solrconfig.xml excerpt for reference: > > texts > AnalyzingInfixLookupFactory > HighFrequencyDictionaryFactory > > suggestion > suggestion_text > false > true > true > false > 0.0 > > > Thanks for your help, > Moe