lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Moritz Schmidt <moritz.schm...@spektrum.de>
Subject Re: Custom search in own SearchComponent
Date Mon, 04 Mar 2019 09:30:28 GMT
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" <mkhl@apache.org>:

    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 <moritz.schmidt@spektrum.de>
    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<Document> specialDocs = new ArrayList<Document>();
    >
    >       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.
Mime
View raw message