Dear Mattias, I have updated to M05, All the enhancements work ok.
Thanks a lot for the great job. 2010/11/21 Mattias Persson <[email protected]> > I've done some stuff regarding this: > > > - Added "similarity" configuration parameter (although not very tested > since I don't really know how lucene similarity works). > - Added QueryContext#topDocs(int) which you can set so that only top N > hits are retrieved instead of all (may or may not be a performance > improvement in some scenarios). > - Added IndexHits#currentScore() so that lucene scores are exposed > (although not stuff that's added, but not yet committed, in the current > neo4j transaction if such is open). > > I also found some minor performance improvements while doing all this. It'd > be wonderful to have you try this out and tell about how it works out. > > These changes will be in the next milestone M05, but you can get latest > snapshots, as we speak, from our repositories. > > 2010/11/19 Samuel Feng <[email protected]> > > > I think it is ok. It is good no need to use a Similarity instance for > each > > query. > > > > 2010/11/19 Mattias Persson <[email protected]> > > > > > There's also a problem going with the QueryContext approach... an > > > IndexSearcher can be shared by multiple threads and multiple queries so > > > using IndexSearcher#setSimilarity can't be done on a per-query basis. > > > Setting a similarity in one query may also set it for another > > thread/query > > > which might not want it. So maybe the only option is to go with the > > > configuration parameter, so that all IndexWriters and IndexSearchers > for > > > that index gets that Similarity instance set. > > > > > > WDYT? > > > > > > 2010/11/18 Mattias Persson <[email protected]> > > > > > > > Allright, then there probably have to be a configuration parameter > for > > > > similarity, and maybe something in QueryContext as well (if you > > wouldn't > > > use > > > > the configuration parameter). > > > > > > > > > > > > 2010/11/18 Samuel Feng <[email protected]> > > > > > > > >> From > > > >> > > > >> > > > > > > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/Similarity.html > > > >> > > > >> < > > > >> > > > > > > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/Similarity.html > > > >> >If > > > >> the custom Similarity overwrite the > > > >> *lengthNorm< > > > >> > > > > > > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/Similarity.html#lengthNorm(java.lang.String > < > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/Similarity.html#lengthNorm%28java.lang.String > > > > > < > > > > > > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/Similarity.html#lengthNorm%28java.lang.String > > > > > > > >> , > > > >> int)>*(field)< > > > >> > > > > > > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/Similarity.html#lengthNorm(java.lang.String > < > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/Similarity.html#lengthNorm%28java.lang.String > > > > > < > > > > > > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/Similarity.html#lengthNorm%28java.lang.String > > > > > > > >> , > > > >> int)> method of DefaultSimilarity, need to set the Similarity during > > > >> writing > > > >> index. > > > >> > > > >> > > > >> 2010/11/19 Mattias Persson <[email protected]> > > > >> > > > >> > 2010/11/18 Samuel Feng <[email protected]> > > > >> > > > > >> > > Hi, > > > >> > > > > > >> > > To my understanding, if you use one > > > >> > > Similarity in indexWriter, you should also use it in > > indexSearcher. > > > >> > > > > > >> > > And the scoring is not written during writing index, as it > depends > > > on > > > >> the > > > >> > > relationship between query terms and the indexed documents. It > is > > > >> > > calculated > > > >> > > for each query. > > > >> > > > > > >> > > > > >> > But is it a benefit to use it in writer and/or searcher? Is the > > > >> similarity > > > >> > needed at all during writing? > > > >> > > > > >> > > > > >> > > > > > >> > > > > > >> > > 2010/11/18 Mattias Persson <[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 > > > >> > > > >> > > > >> > > > > > > > >> > > > Btw, what's the difference between setting Similarity on > > > IndexWriter > > > >> > vs. > > > >> > > > IndexSearcher? Is it performance maybe, that if it's set on > the > > > >> > > IndexWriter > > > >> > > > then the scoring is written during writes, but if it's set on > > > >> > > IndexSearcher > > > >> > > > it's calculated for each query? > > > >> > > > _______________________________________________ > > > >> > > > Neo4j mailing list > > > >> > > > [email protected] > > > >> > > > https://lists.neo4j.org/mailman/listinfo/user > > > >> > > > > > > >> > > _______________________________________________ > > > >> > > 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 > > > >> > > > > >> _______________________________________________ > > > >> Neo4j mailing list > > > >> [email protected] > > > >> https://lists.neo4j.org/mailman/listinfo/user > > > >> > > > > > > > > > > > > > > > > -- > > > > Mattias Persson, [[email protected]] > > > > Hacker, Neo Technology > > > > www.neotechnology.com > > > > > > > > > > > > > > > > -- > > > Mattias Persson, [[email protected]] > > > Hacker, Neo Technology > > > www.neotechnology.com > > > _______________________________________________ > > > Neo4j mailing list > > > [email protected] > > > https://lists.neo4j.org/mailman/listinfo/user > > > > > _______________________________________________ > > 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 > _______________________________________________ Neo4j mailing list [email protected] https://lists.neo4j.org/mailman/listinfo/user

