Announcement Announcement Module
Collapse
No announcement yet.
Change Lucene Default SImilarity in Neo4j Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change Lucene Default SImilarity in Neo4j

    I'm using Neo4j (1.9) and lucene core 3.5, through the support offered by the neo4j-lucene-index library. In my code, I create a new node index like that:

    Code:
        HashMap<String, String> stringMap = new HashMap<String, String>();
            stringMap.put("type", "fulltext");
        stringMap.put(IndexManager.PROVIDER, "lucene");
        stringMap.put("to_lower_case", "false");
        stringMap.put("similarity", MySimilarity.class.getName());
        stringMap.put("analyzer", MyAnalyzer.class.getName());
        simpleIndex = (LuceneIndex<Node>) template.getGraphDatabaseService()
                .index().forNodes("simple-index", stringMap);
    and query the node index by means of a multi-field query:
    Code:
     
        Analyzer analyzer = new MyAnalyzer();
        Query query = null;
        try {
            query = MultiFieldQueryParser.parse(Version.LUCENE_35,
                    queriesArray, fieldsArray, flagsArray, analyzer);
        } catch (ParseException e) {
            e.printStackTrace();
            return;
        }
        if (query == null)
            return;
        QueryContext qc = new QueryContext(query).sortByScore();
        IndexHits<Node> hits = simpleIndex.query(qc);
    How can I change the Similarity implementation used for sorting by score to MySimilarity class (which extends the DefaultSimilarity and overrides some of its methods)? The reported query always uses the DefaultSimilarity and I was not able to find any hook to set the similarity used by the searcher activated during my query.
Working...
X