2010/11/13 Samuel Feng <[email protected]> > Hi, > > I am new to neo4j. > > I am using a custom analyzer in index in order to support Chinese. > > chnIndex = this.graphDb.index().forNodes("product_chinese", > MapUtil.stringMap("analyzer", > "org.wltea.analyzer.lucene.IKAnalyzer")); > > Below is the usage of the IKAnalyzer in lucence. > > IndexSearcher isearcher = new IndexSearcher(directory); > isearcher.setSimilarity(new IKSimilarity()); // A custom Similarity > String word = "OLYMPUS 奥林巴斯 E-PL1 时尚白 微型4/3系统相机 套机 含14-42mm镜头"; > Query query = IKQueryParser.parse(fieldName, word ); // A custom > QueryParser > TopDocs topDocs = isearcher.search(query, 5); // Got the top 5 > System.out.println("Found " + topDocs.totalHits); > ScoreDoc[] scoreDocs = topDocs.scoreDocs; > for (int i = 0; i < topDocs.totalHits; i++) { > System.out.println(scoreDocs[i].score); // Got the score of each > matched doc > Document targetDoc = isearcher.doc(scoreDocs[i].doc); > System.out.println("Document content is " + targetDoc.toString()); > } > > How can I use the query method of neo4j's indexing to implement > 1) Add my custom Similartiy implemtation >
That would require new functionality, probably exposed as a configuration parameter "similarity":"org.wltea.analyzer.lucene.IKAnalyzer" or something. > 2) The TopDocs interface can replaced by the iterator of IndexHits, right? > In a way, yes. Actually IndexHits wraps a Hits instance (from lucene 2.x), since it gives all the hits back. To make use of TopDocs instead a method could be exposed via the QueryContext class. That's definately possible. > 3) Possible to get the score for each node in the IndexHits? > Would it be ok with an IndexHits#currentScore() method which could return the score of the most recently returned node from the IndexHits object? > > Thank you for the help and time spent on this. > These are great ideas and I'd be happy to try and implement them. > > Samuel > _______________________________________________ > Neo4j mailing list > [email protected] > https://lists.neo4j.org/mailman/listinfo/user > -- Mattias Persson, [[email protected]] Hacker, Neo Technology www.neotechnology.com _______________________________________________ Neo4j mailing list [email protected] https://lists.neo4j.org/mailman/listinfo/user

