Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...