[ 
https://issues.apache.org/jira/browse/LUCENE-7931?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16162421#comment-16162421
 ] 

jin jing commented on LUCENE-7931:
----------------------------------

 public static void main(String[] args) throws IOException {  
        Directory dir = new RAMDirectory();  
        Analyzer analyzer = new StandardAnalyzer();  
        IndexWriterConfig iwc = new IndexWriterConfig(analyzer);  
        iwc.setOpenMode(OpenMode.CREATE);  
        IndexWriter writer = new IndexWriter(dir, iwc);  
  
        Document doc = new Document();  
        doc.add(new TextField("text", "the quick brown fox jumps over the lazy 
dog", Field.Store.YES));  
        writer.addDocument(doc);  
          
        doc = new Document();  
        doc.add(new TextField("text", "the quick red fox jumps over the sleepy 
cat", Field.Store.YES));  
        writer.addDocument(doc);  
          
        doc = new Document();  
        doc.add(new TextField("text", "the quick brown fox jumps over the lazy 
not dog", Field.Store.YES));  
        writer.addDocument(doc);  
        writer.close(); 
        IndexReader reader = DirectoryReader.open(dir);  
        IndexSearcher searcher = new IndexSearcher(reader);  
        String queryStringStart = "dog";  
        String queryStringEnd = "quick";  
        String excludeString = "not";  
        SpanQuery queryStart = new SpanTermQuery(new 
Term("text",queryStringStart));  
        SpanQuery queryEnd = new SpanTermQuery(new 
Term("text",queryStringEnd));  
        SpanQuery excludeQuery = new SpanTermQuery(new 
Term("text",excludeString));  
        SpanQuery spanNearQuery = new SpanNearQuery(  
            new SpanQuery[] {queryStart,queryEnd}, 9, false, false);  
          
        SpanNotQuery spanNotQuery = new SpanNotQuery(spanNearQuery, 
excludeQuery, 4,3);  
        TopDocs results = searcher.search(spanNotQuery, null, 100);  
        ScoreDoc[] scoreDocs = results.scoreDocs;  
          
        for (int i = 0; i < scoreDocs.length; ++i) {  
            int docID = scoreDocs[i].doc;  
            Document document = searcher.doc(docID);  
            String path = document.get("text");  
            System.out.println("text:" + path);  
        }  
    }  

> SpanNotQuery  has bug?
> ----------------------
>
>                 Key: LUCENE-7931
>                 URL: https://issues.apache.org/jira/browse/LUCENE-7931
>             Project: Lucene - Core
>          Issue Type: Bug
>          Components: core/search
>    Affects Versions: 5.3.1
>            Reporter: jin jing
>
> i find when use SpanNotQuery and the exclud key word like  "not"  "or"  will 
> give a error result
> example:
> doc1:the quick brown fox jumps over the lazy dog
> doc2:the quick red fox jumps over the sleepy cat
> doc3:the quick brown fox jumps over the lazy NOT dog
> String queryStringStart = "dog";  
> String queryStringEnd = "quick";  
> String excludeString = "NOT";  
> SpanQuery queryStart = new SpanTermQuery(new Term("text",queryStringStart));  
> SpanQuery queryEnd = new SpanTermQuery(new Term("text",queryStringEnd));  
> SpanQuery excludeQuery = new SpanTermQuery(new Term("text",excludeString));  
> SpanQuery spanNearQuery = new SpanNearQuery(  
>             new SpanQuery[] {queryStart,queryEnd}, 7, false, false);  
>           
>  SpanNotQuery spanNotQuery = new SpanNotQuery(spanNearQuery, excludeQuery, 
> 4,3); 
> then  this will return doc1 and doc3.  so i think it is a bug. 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to