本文整理汇总了Java中net.semanticmetadata.lire.DocumentBuilder.FIELD_NAME_FCTH属性的典型用法代码示例。如果您正苦于以下问题:Java DocumentBuilder.FIELD_NAME_FCTH属性的具体用法?Java DocumentBuilder.FIELD_NAME_FCTH怎么用?Java DocumentBuilder.FIELD_NAME_FCTH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类net.semanticmetadata.lire.DocumentBuilder
的用法示例。
在下文中一共展示了DocumentBuilder.FIELD_NAME_FCTH属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFieldName
@Override
public String getFieldName() {
return DocumentBuilder.FIELD_NAME_FCTH;
}
示例2: testSearch
public void testSearch() throws IOException, ParseException {
// create a Lucene IndexReader and the according IndexSearcher:
IndexReader reader = DirectoryReader.open(FSDirectory.open(testIndex));
IndexSearcher searcher = new IndexSearcher(reader);
// The QueryParser takes a String and creates a query out of it. Make sure you use the same field
// as for indexing, in this case "tags"
QueryParser q = new QueryParser(Version.LUCENE_42, "tags", new SimpleAnalyzer(Version.LUCENE_42));
// let's just take the tags of the first document in the index:
Query query = q.parse(reader.document(1).getValues("tags")[0]);
// now that's the actual search:
// NOTE: The number of results here is critical. The less documents are returned here, the
// less the image re-ranking can mess up. However, the recall (the absolute number of relevant
// documents returned) is also influenced by this. Best to try several values like 10, 100, 200, 500, ...
TopDocs results = searcher.search(query, 10);
// here we print the results of the text search, just for the win.
System.out.println("-----------> SEARCH RESULTS ...");
for (int i = 0; i < results.scoreDocs.length; i++) {
ScoreDoc scoreDoc = results.scoreDocs[i];
System.out.print(scoreDoc.score + "\t: ");
// reader.document(scoreDoc.doc).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0] gets you the actual image file path.
// LIRE manages all needed filed names as static Strings in DocumentBuilder ...
System.out.print(reader.document(scoreDoc.doc).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0] + " -> ");
System.out.println(reader.document(scoreDoc.doc).getValues("tags")[0]);
}
// just for a visual example ... this will pop up a browser window
FileUtils.browseUri(FileUtils.saveImageResultsToHtml("text", results, reader, reader.document(1).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]));
// and now for the re-ranking:
// make sure to use a low level feature that has been indexed -- check the DocumentBuilder in above method.
RerankFilter rerank = new RerankFilter(FCTH.class, DocumentBuilder.FIELD_NAME_FCTH);
// note that you need the document here, it contains the low level feature ...
// if you don't have it but just the image you need to create a new one with the
// appropriate DocumentBuilder -- check the DocumentBuilder in above method.
ImageSearchHits hitsReranked = rerank.filter(results, reader, reader.document(1));
// and here we print the re-ranked hits:
System.out.println("-----------> RERANKED ...");
for (int i = 0; i < hitsReranked.length(); i++) {
System.out.print(hitsReranked.score(i) + "\t: ");
System.out.print(hitsReranked.doc(i).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0] + " -> ");
System.out.println(hitsReranked.doc(i).getValues("tags")[0]);
}
// just for a visual example ... this will pop up a browser window.
FileUtils.browseUri(FileUtils.saveImageResultsToHtml("reranked", hitsReranked, reader.document(1).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]));
}