Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
655 views
in Technique[技术] by (71.8m points)

solr - Lucene how to search on multivalued field?

I created multivalued field in schema.xml:

<field name="path" type="pint" multiValued="true" indexed="true" stored="true"/>

I created my own search component class like this:

public class CustomComponent extends SearchComponent {


    private static final Logger LOG = LoggerFactory.getLogger(CustomComponent.class);

    @Override
    public void prepare(ResponseBuilder rb) throws IOException {

    }

    @Override
    public void process(ResponseBuilder rb) throws IOException {
        LOG.info("CustomComponent running ---");

        SolrParams params = rb.req.getParams();
        

        CoreContainer coreContainer = rb.req.getCore().getCoreContainer();
        SolrCore solrCore = coreContainer.getCore("example_core");
        SolrIndexSearcher categorySearcher = solrCore.getSearcher().get();
        IndexReader categoryReader = categorySearcher.getIndexReader();
        
        String pathId = params.get("pathId"); //3
        FieldType path = solrCore.getLatestSchema().getField("path").getType();

        StandardQueryParser standardQueryParser = new StandardQueryParser();
        standardQueryParser.setAnalyzer(path.getQueryAnalyzer());

        Query q = standardQueryParser.parse(pathId, "path");

        DocList docList = searcher.getDocList(q, null, null, 0, 1000, 1000);
        LOG.info(docListsize()); // returns 0 
        //even if there is a document which has field with such value

        }
    }

What is wrong here? Is there a way to search on multivalued field? Thanks for answer in advance.

question from:https://stackoverflow.com/questions/65833564/lucene-how-to-search-on-multivalued-field

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...