Exemple #1
0
		public QueryTermVector(System.String queryString, Analyzer analyzer)
		{
			if (analyzer != null)
			{
				TokenStream stream = analyzer.TokenStream("", new System.IO.StringReader(queryString));
				if (stream != null)
				{
					System.Collections.ArrayList terms = new System.Collections.ArrayList();
					try
					{
						bool hasMoreTokens = false;
						
						stream.Reset();
						TermAttribute termAtt = (TermAttribute) stream.AddAttribute(typeof(TermAttribute));
						
						hasMoreTokens = stream.IncrementToken();
						while (hasMoreTokens)
						{
							terms.Add(termAtt.Term());
							hasMoreTokens = stream.IncrementToken();
						}
						ProcessTerms((System.String[]) terms.ToArray(typeof(System.String)));
					}
					catch (System.IO.IOException e)
					{
					}
				}
			}
		}
Exemple #2
0
        public QueryTermVector(System.String queryString, Analyzer analyzer)
        {
            if (analyzer != null)
            {
                TokenStream stream = analyzer.TokenStream("", new System.IO.StringReader(queryString));
                if (stream != null)
                {
                    System.Collections.ArrayList terms = new System.Collections.ArrayList();
                    try
                    {
                        bool hasMoreTokens = false;

                        stream.Reset();
                        TermAttribute termAtt = (TermAttribute)stream.AddAttribute(typeof(TermAttribute));

                        hasMoreTokens = stream.IncrementToken();
                        while (hasMoreTokens)
                        {
                            terms.Add(termAtt.Term());
                            hasMoreTokens = stream.IncrementToken();
                        }
                        ProcessTerms((System.String[])terms.ToArray(typeof(System.String)));
                    }
                    catch (System.IO.IOException e)
                    {
                    }
                }
            }
        }
Exemple #3
0
        /// <summary> Open an index with write access.
        ///
        /// </summary>
        /// <param name="dirName">the index directory
        /// </param>
        /// <param name="analyzer">the analyzer to use for adding new documents
        /// </param>
        /// <param name="create"><code>true</code> to create the index or overwrite the existing one;
        /// <code>false</code> to append to the existing index
        /// </param>
        /// <throws>  CorruptIndexException if the index is corrupt </throws>
        /// <throws>  LockObtainFailedException if another writer </throws>
        /// <summary>  has this index open (<code>write.lock</code> could not
        /// be obtained)
        /// </summary>
        /// <throws>  IOException if there is a low-level IO error </throws>
        public IndexModifier(System.String dirName, Analyzer analyzer, bool create)
        {
            InitBlock();
            Directory dir = FSDirectory.GetDirectory(dirName);

            this.closeDir = true;
            Init(dir, analyzer, create);
        }
Exemple #4
0
        /// <summary> Open an index with write access.
        ///
        /// </summary>
        /// <param name="file">the index directory
        /// </param>
        /// <param name="analyzer">the analyzer to use for adding new documents
        /// </param>
        /// <param name="create"><code>true</code> to create the index or overwrite the existing one;
        /// <code>false</code> to append to the existing index
        /// </param>
        /// <throws>  CorruptIndexException if the index is corrupt </throws>
        /// <throws>  LockObtainFailedException if another writer </throws>
        /// <summary>  has this index open (<code>write.lock</code> could not
        /// be obtained)
        /// </summary>
        /// <throws>  IOException if there is a low-level IO error </throws>
        public IndexModifier(System.IO.FileInfo file, Analyzer analyzer, bool create)
        {
            InitBlock();
            Directory dir = FSDirectory.GetDirectory(file);

            this.closeDir = true;
            Init(dir, analyzer, create);
        }
Exemple #5
0
 /// <summary> Initialize an IndexWriter.</summary>
 /// <throws>  CorruptIndexException if the index is corrupt </throws>
 /// <throws>  LockObtainFailedException if another writer </throws>
 /// <summary>  has this index open (<code>write.lock</code> could not
 /// be obtained)
 /// </summary>
 /// <throws>  IOException if there is a low-level IO error </throws>
 protected internal virtual void  Init(Directory directory, Analyzer analyzer, bool create)
 {
     this.directory = directory;
     lock (this.directory)
     {
         this.analyzer = analyzer;
         indexWriter   = new IndexWriter(directory, analyzer, create, IndexWriter.MaxFieldLength.LIMITED);
         open          = true;
     }
 }
Exemple #6
0
 /// <summary> Adds a document to this index, using the provided analyzer instead of the
 /// one specific in the constructor.  If the document contains more than
 /// {@link #SetMaxFieldLength(int)} terms for a given field, the remainder are
 /// discarded.
 /// </summary>
 /// <seealso cref="IndexWriter.AddDocument(Document, Analyzer)">
 /// </seealso>
 /// <throws>  IllegalStateException if the index is closed </throws>
 /// <throws>  CorruptIndexException if the index is corrupt </throws>
 /// <throws>  LockObtainFailedException if another writer </throws>
 /// <summary>  has this index open (<code>write.lock</code> could not
 /// be obtained)
 /// </summary>
 /// <throws>  IOException if there is a low-level IO error </throws>
 public virtual void  AddDocument(Document doc, Analyzer docAnalyzer)
 {
     lock (directory)
     {
         AssureOpen();
         CreateIndexWriter();
         if (docAnalyzer != null)
         {
             indexWriter.AddDocument(doc, docAnalyzer);
         }
         else
         {
             indexWriter.AddDocument(doc);
         }
     }
 }
 /// <summary> Creates a MultiFieldQueryParser.
 ///
 /// <p/>
 /// It will, when parse(String query) is called, construct a query like this
 /// (assuming the query consists of two terms and you specify the two fields
 /// <code>title</code> and <code>body</code>):
 /// <p/>
 ///
 /// <code>
 /// (title:term1 body:term1) (title:term2 body:term2)
 /// </code>
 ///
 /// <p/>
 /// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
 /// <p/>
 ///
 /// <code>
 /// +(title:term1 body:term1) +(title:term2 body:term2)
 /// </code>
 ///
 /// <p/>
 /// In other words, all the query's terms must appear, but it doesn't matter
 /// in what fields they appear.
 /// <p/>
 /// </summary>
 public MultiFieldQueryParser(Version matchVersion, System.String[] fields, Analyzer analyzer) : base(matchVersion, null, analyzer)
 {
     this.fields = fields;
 }
 public static Query Parse(System.String[] queries, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
 {
     return(Parse(Version.LUCENE_24, queries, fields, flags, analyzer));
 }
Exemple #9
0
		public QueryParser(System.String f, Analyzer a):this(Version.LUCENE_24, f, a)
		{
		}
 /// <summary> Creates a MultiFieldQueryParser. Allows passing of a map with term to
 /// Boost, and the boost to apply to each term.
 ///
 /// <p/>
 /// It will, when parse(String query) is called, construct a query like this
 /// (assuming the query consists of two terms and you specify the two fields
 /// <code>title</code> and <code>body</code>):
 /// <p/>
 ///
 /// <code>
 /// (title:term1 body:term1) (title:term2 body:term2)
 /// </code>
 ///
 /// <p/>
 /// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
 /// <p/>
 ///
 /// <code>
 /// +(title:term1 body:term1) +(title:term2 body:term2)
 /// </code>
 ///
 /// <p/>
 /// When you pass a boost (title=>5 body=>10) you can get
 /// <p/>
 ///
 /// <code>
 /// +(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)
 /// </code>
 ///
 /// <p/>
 /// In other words, all the query's terms must appear, but it doesn't matter
 /// in what fields they appear.
 /// <p/>
 /// </summary>
 public MultiFieldQueryParser(Version matchVersion, System.String[] fields, Analyzer analyzer, System.Collections.IDictionary boosts) : this(matchVersion, fields, analyzer)
 {
     this.boosts = boosts;
 }
		/// <summary> Parses a query, searching on the fields specified. Use this if you need
		/// to specify certain fields as required, and others as prohibited.
		/// <p/>
		/// 
		/// <pre>
		/// Usage:
		/// &lt;code&gt;
		/// String[] query = {&quot;query1&quot;, &quot;query2&quot;, &quot;query3&quot;};
		/// String[] fields = {&quot;filename&quot;, &quot;contents&quot;, &quot;description&quot;};
		/// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
		/// BooleanClause.Occur.MUST,
		/// BooleanClause.Occur.MUST_NOT};
		/// MultiFieldQueryParser.parse(query, fields, flags, analyzer);
		/// &lt;/code&gt;
		/// </pre>
		/// <p/>
		/// The code above would construct a query:
		/// 
		/// <pre>
		/// &lt;code&gt;
		/// (filename:query1) +(contents:query2) -(description:query3)
		/// &lt;/code&gt;
		/// </pre>
		/// 
		/// </summary>
		/// <param name="matchVersion">Lucene version to match; this is passed through to
		/// QueryParser.
		/// </param>
		/// <param name="queries">Queries string to parse
		/// </param>
		/// <param name="fields">Fields to search on
		/// </param>
		/// <param name="flags">Flags describing the fields
		/// </param>
		/// <param name="analyzer">Analyzer to use
		/// </param>
		/// <throws>  ParseException </throws>
		/// <summary>             if query parsing fails
		/// </summary>
		/// <throws>  IllegalArgumentException </throws>
		/// <summary>             if the length of the queries, fields, and flags array differ
		/// </summary>
		public static Query Parse(Version matchVersion, System.String[] queries, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
		{
			if (!(queries.Length == fields.Length && queries.Length == flags.Length))
				throw new System.ArgumentException("queries, fields, and flags array have have different length");
			BooleanQuery bQuery = new BooleanQuery();
			for (int i = 0; i < fields.Length; i++)
			{
				QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
				Query q = qp.Parse(queries[i]);
				if (q != null && (!(q is BooleanQuery) || ((BooleanQuery) q).GetClauses().Length > 0))
				{
					bQuery.Add(q, flags[i]);
				}
			}
			return bQuery;
		}
Exemple #12
0
		public IndexWriter(System.IO.FileInfo path, Analyzer a, MaxFieldLength mfl)
		{
			InitBlock();
			Init(FSDirectory.GetDirectory(path), a, true, null, false, mfl.GetLimit(), null, null);
		}
Exemple #13
0
		private void  Init(Directory d, Analyzer a, bool closeDir, IndexDeletionPolicy deletionPolicy, bool autoCommit, int maxFieldLength, IndexingChain indexingChain, IndexCommit commit)
		{
			if (IndexReader.IndexExists(d))
			{
				Init(d, a, false, closeDir, deletionPolicy, autoCommit, maxFieldLength, indexingChain, commit);
			}
			else
			{
				Init(d, a, true, closeDir, deletionPolicy, autoCommit, maxFieldLength, indexingChain, commit);
			}
		}
Exemple #14
0
		public IndexWriter(Directory d, Analyzer a)
		{
			InitBlock();
			Init(d, a, false, null, true, DEFAULT_MAX_FIELD_LENGTH, null, null);
		}
Exemple #15
0
		public IndexWriter(Directory d, bool autoCommit, Analyzer a, bool create, IndexDeletionPolicy deletionPolicy)
		{
			InitBlock();
			Init(d, a, create, false, deletionPolicy, autoCommit, DEFAULT_MAX_FIELD_LENGTH, null, null);
		}
Exemple #16
0
		/// <summary> Expert: constructs an IndexWriter on specific commit
		/// point, with a custom {@link IndexDeletionPolicy}, for
		/// the index in <code>d</code>.  Text will be analyzed
		/// with <code>a</code>.
		/// 
		/// <p/> This is only meaningful if you've used a {@link
		/// IndexDeletionPolicy} in that past that keeps more than
		/// just the last commit.
		/// 
		/// <p/>This operation is similar to {@link #Rollback()},
		/// except that method can only rollback what's been done
		/// with the current instance of IndexWriter since its last
		/// commit, whereas this method can rollback to an
		/// arbitrary commit point from the past, assuming the
		/// {@link IndexDeletionPolicy} has preserved past
		/// commits.
		/// 
		/// <p/><b>NOTE</b>: autoCommit (see <a
		/// href="#autoCommit">above</a>) is set to false with this
		/// constructor.
		/// 
		/// </summary>
		/// <param name="d">the index directory
		/// </param>
		/// <param name="a">the analyzer to use
		/// </param>
		/// <param name="deletionPolicy">see <a href="#deletionPolicy">above</a>
		/// </param>
		/// <param name="mfl">whether or not to limit field lengths, value is in number of terms/tokens.  See {@link Mono.Lucene.Net.Index.IndexWriter.MaxFieldLength}.
		/// </param>
		/// <param name="commit">which commit to open
		/// </param>
		/// <throws>  CorruptIndexException if the index is corrupt </throws>
		/// <throws>  LockObtainFailedException if another writer </throws>
		/// <summary>  has this index open (<code>write.lock</code> could not
		/// be obtained)
		/// </summary>
		/// <throws>  IOException if the directory cannot be read/written to, or </throws>
		/// <summary>  if it does not exist and <code>create</code> is
		/// <code>false</code> or if there is any other low-level
		/// IO error
		/// </summary>
		public IndexWriter(Directory d, Analyzer a, IndexDeletionPolicy deletionPolicy, MaxFieldLength mfl, IndexCommit commit)
		{
			InitBlock();
			Init(d, a, false, false, deletionPolicy, false, mfl.GetLimit(), null, commit);
		}
Exemple #17
0
		/// <summary> Expert: constructs an IndexWriter with a custom {@link
		/// IndexDeletionPolicy} and {@link IndexingChain}, 
		/// for the index in <code>d</code>.
		/// Text will be analyzed with <code>a</code>.  If
		/// <code>create</code> is true, then a new, empty index
		/// will be created in <code>d</code>, replacing the index
		/// already there, if any.
		/// 
		/// <p/><b>NOTE</b>: autoCommit (see <a
		/// href="#autoCommit">above</a>) is set to false with this
		/// constructor.
		/// 
		/// </summary>
		/// <param name="d">the index directory
		/// </param>
		/// <param name="a">the analyzer to use
		/// </param>
		/// <param name="create"><code>true</code> to create the index or overwrite
		/// the existing one; <code>false</code> to append to the existing
		/// index
		/// </param>
		/// <param name="deletionPolicy">see <a href="#deletionPolicy">above</a>
		/// </param>
		/// <param name="mfl">whether or not to limit field lengths, value is in number of terms/tokens.  See {@link Mono.Lucene.Net.Index.IndexWriter.MaxFieldLength}.
		/// </param>
		/// <param name="indexingChain">the {@link DocConsumer} chain to be used to 
		/// process documents
		/// </param>
		/// <param name="commit">which commit to open
		/// </param>
		/// <throws>  CorruptIndexException if the index is corrupt </throws>
		/// <throws>  LockObtainFailedException if another writer </throws>
		/// <summary>  has this index open (<code>write.lock</code> could not
		/// be obtained)
		/// </summary>
		/// <throws>  IOException if the directory cannot be read/written to, or </throws>
		/// <summary>  if it does not exist and <code>create</code> is
		/// <code>false</code> or if there is any other low-level
		/// IO error
		/// </summary>
		internal IndexWriter(Directory d, Analyzer a, bool create, IndexDeletionPolicy deletionPolicy, MaxFieldLength mfl, IndexingChain indexingChain, IndexCommit commit)
		{
			InitBlock();
			Init(d, a, create, false, deletionPolicy, false, mfl.GetLimit(), indexingChain, commit);
		}
Exemple #18
0
		/// <summary> Expert: constructs an IndexWriter with a custom {@link
		/// IndexDeletionPolicy}, for the index in <code>d</code>.
		/// Text will be analyzed with <code>a</code>.  If
		/// <code>create</code> is true, then a new, empty index
		/// will be created in <code>d</code>, replacing the index
		/// already there, if any.
		/// 
		/// <p/><b>NOTE</b>: autoCommit (see <a
		/// href="#autoCommit">above</a>) is set to false with this
		/// constructor.
		/// 
		/// </summary>
		/// <param name="d">the index directory
		/// </param>
		/// <param name="a">the analyzer to use
		/// </param>
		/// <param name="create"><code>true</code> to create the index or overwrite
		/// the existing one; <code>false</code> to append to the existing
		/// index
		/// </param>
		/// <param name="deletionPolicy">see <a href="#deletionPolicy">above</a>
		/// </param>
		/// <param name="mfl">{@link Mono.Lucene.Net.Index.IndexWriter.MaxFieldLength}, whether or not to limit field lengths.  Value is in number of terms/tokens
		/// </param>
		/// <throws>  CorruptIndexException if the index is corrupt </throws>
		/// <throws>  LockObtainFailedException if another writer </throws>
		/// <summary>  has this index open (<code>write.lock</code> could not
		/// be obtained)
		/// </summary>
		/// <throws>  IOException if the directory cannot be read/written to, or </throws>
		/// <summary>  if it does not exist and <code>create</code> is
		/// <code>false</code> or if there is any other low-level
		/// IO error
		/// </summary>
		public IndexWriter(Directory d, Analyzer a, bool create, IndexDeletionPolicy deletionPolicy, MaxFieldLength mfl)
		{
			InitBlock();
			Init(d, a, create, false, deletionPolicy, false, mfl.GetLimit(), null, null);
		}
Exemple #19
0
		public IndexWriter(Directory d, bool autoCommit, Analyzer a)
		{
			InitBlock();
			Init(d, a, false, null, autoCommit, DEFAULT_MAX_FIELD_LENGTH, null, null);
		}
 public MultiFieldQueryParser(System.String[] fields, Analyzer analyzer, System.Collections.IDictionary boosts) : this(Version.LUCENE_24, fields, analyzer)
 {
     this.boosts = boosts;
 }
Exemple #21
0
		private void  Init(Directory d, Analyzer a, bool create, bool closeDir, IndexDeletionPolicy deletionPolicy, bool autoCommit, int maxFieldLength, IndexingChain indexingChain, IndexCommit commit)
		{
			this.closeDir = closeDir;
			directory = d;
			analyzer = a;
			SetMessageID(defaultInfoStream);
			this.maxFieldLength = maxFieldLength;
			
			if (indexingChain == null)
				indexingChain = DocumentsWriter.DefaultIndexingChain;
			
			if (create)
			{
				// Clear the write lock in case it's leftover:
				directory.ClearLock(WRITE_LOCK_NAME);
			}
			
			Lock writeLock = directory.MakeLock(WRITE_LOCK_NAME);
			if (!writeLock.Obtain(writeLockTimeout))
			// obtain write lock
			{
				throw new LockObtainFailedException("Index locked for write: " + writeLock);
			}
			this.writeLock = writeLock; // save it

            bool success = false;
			try
			{
				if (create)
				{
					// Try to read first.  This is to allow create
					// against an index that's currently open for
					// searching.  In this case we write the next
					// segments_N file with no segments:
					bool doCommit;
					try
					{
						segmentInfos.Read(directory);
						segmentInfos.Clear();
						doCommit = false;
					}
					catch (System.IO.IOException e)
					{
						// Likely this means it's a fresh directory
						doCommit = true;
					}
					
					if (autoCommit || doCommit)
					{
						// Always commit if autoCommit=true, else only
						// commit if there is no segments file in this dir
						// already.
						segmentInfos.Commit(directory);
						SupportClass.CollectionsHelper.AddAllIfNotContains(synced, segmentInfos.Files(directory, true));
					}
					else
					{
						// Record that we have a change (zero out all
						// segments) pending:
						changeCount++;
					}
				}
				else
				{
					segmentInfos.Read(directory);
					
					if (commit != null)
					{
						// Swap out all segments, but, keep metadata in
						// SegmentInfos, like version & generation, to
						// preserve write-once.  This is important if
						// readers are open against the future commit
						// points.
						if (commit.GetDirectory() != directory)
							throw new System.ArgumentException("IndexCommit's directory doesn't match my directory");
						SegmentInfos oldInfos = new SegmentInfos();
						oldInfos.Read(directory, commit.GetSegmentsFileName());
						segmentInfos.Replace(oldInfos);
						changeCount++;
						if (infoStream != null)
							Message("init: loaded commit \"" + commit.GetSegmentsFileName() + "\"");
					}
					
					// We assume that this segments_N was previously
					// properly sync'd:
					SupportClass.CollectionsHelper.AddAllIfNotContains(synced, segmentInfos.Files(directory, true));
				}
				
				this.autoCommit = autoCommit;
				SetRollbackSegmentInfos(segmentInfos);
				
				docWriter = new DocumentsWriter(directory, this, indexingChain);
				docWriter.SetInfoStream(infoStream);
				docWriter.SetMaxFieldLength(maxFieldLength);
				
				// Default deleter (for backwards compatibility) is
				// KeepOnlyLastCommitDeleter:
				deleter = new IndexFileDeleter(directory, deletionPolicy == null?new KeepOnlyLastCommitDeletionPolicy():deletionPolicy, segmentInfos, infoStream, docWriter,synced);
				
				if (deleter.startingCommitDeleted)
				// Deletion policy deleted the "head" commit point.
				// We have to mark ourself as changed so that if we
				// are closed w/o any further changes we write a new
				// segments_N file.
					changeCount++;
				
				PushMaxBufferedDocs();
				
				if (infoStream != null)
				{
					Message("init: create=" + create);
					MessageState();
				}

                success = true;
			}
			finally
			{
                if (!success)
                {
                    if (infoStream != null)
                    {
                        Message("init: hit exception on init; releasing write lock");
                    }
                    try
                    {
                        writeLock.Release();
                    }
                    catch (Exception t)
                    {
                        // don't mask the original exception
                    }
                    writeLock = null;
                }
			}
		}
Exemple #22
0
        public IndexWriter(System.String path, Analyzer a, bool create, MaxFieldLength mfl)
		{
			InitBlock();
			Init(FSDirectory.GetDirectory(path), a, create, true, null, false, mfl.GetLimit(), null, null);
		}
Exemple #23
0
		/// <summary> Updates a document by first deleting the document(s)
		/// containing <code>term</code> and then adding the new
		/// document.  The delete and then add are atomic as seen
		/// by a reader on the same index (flush may happen only after
		/// the add).
		/// 
		/// <p/><b>NOTE</b>: if this method hits an OutOfMemoryError
		/// you should immediately close the writer.  See <a
		/// href="#OOME">above</a> for details.<p/>
		/// 
		/// </summary>
		/// <param name="term">the term to identify the document(s) to be
		/// deleted
		/// </param>
		/// <param name="doc">the document to be added
		/// </param>
		/// <param name="analyzer">the analyzer to use when analyzing the document
		/// </param>
		/// <throws>  CorruptIndexException if the index is corrupt </throws>
		/// <throws>  IOException if there is a low-level IO error </throws>
		public virtual void  UpdateDocument(Term term, Document doc, Analyzer analyzer)
		{
			EnsureOpen();
			try
			{
				bool doFlush = false;
				bool success = false;
				try
				{
					doFlush = docWriter.UpdateDocument(term, doc, analyzer);
					success = true;
				}
				finally
				{
					if (!success)
					{
						
						if (infoStream != null)
							Message("hit exception updating document");
						
						lock (this)
						{
							// If docWriter has some aborted files that were
							// never incref'd, then we clean them up here
                            System.Collections.Generic.ICollection<string> files = docWriter.AbortedFiles();
							if (files != null)
								deleter.DeleteNewFiles(files);
						}
					}
				}
				if (doFlush)
					Flush(true, false, false);
			}
			catch (System.OutOfMemoryException oom)
			{
				HandleOOM(oom, "updateDocument");
			}
		}
		public static Query Parse(System.String[] queries, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
		{
			return Parse(Version.LUCENE_24, queries, fields, flags, analyzer);
		}
Exemple #25
0
		/// <summary>Returns true if the caller (IndexWriter) should now
		/// flush. 
		/// </summary>
		internal bool AddDocument(Document doc, Analyzer analyzer)
		{
			return UpdateDocument(doc, analyzer, null);
		}
		public MultiFieldQueryParser(System.String[] fields, Analyzer analyzer, System.Collections.IDictionary boosts):this(Version.LUCENE_24, fields, analyzer)
		{
			this.boosts = boosts;
		}
Exemple #27
0
		internal bool UpdateDocument(Term t, Document doc, Analyzer analyzer)
		{
			return UpdateDocument(doc, analyzer, t);
		}
Exemple #28
0
		public IndexWriter(System.String path, Analyzer a, bool create)
		{
			InitBlock();
			Init(FSDirectory.GetDirectory(path), a, create, true, null, true, DEFAULT_MAX_FIELD_LENGTH, null, null);
		}
Exemple #29
0
		internal bool UpdateDocument(Document doc, Analyzer analyzer, Term delTerm)
		{
			
			// This call is synchronized but fast
			DocumentsWriterThreadState state = GetThreadState(doc, delTerm);
			
			DocState docState = state.docState;
			docState.doc = doc;
			docState.analyzer = analyzer;

            bool doReturnFalse = false; // {{Aroush-2.9}} to handle return from finally clause

			bool success = false;
			try
			{
				// This call is not synchronized and does all the
				// work
				DocWriter perDoc;
                try
                {
                    perDoc = state.consumer.ProcessDocument();
                }
                finally
                {
                    docState.Clear();
                }
				// This call is synchronized but fast
				FinishDocument(state, perDoc);
				success = true;
			}
			finally
			{
				if (!success)
				{
					lock (this)
					{
						
						if (aborting)
						{
							state.isIdle = true;
							System.Threading.Monitor.PulseAll(this);
							Abort();
						}
						else
						{
							skipDocWriter.docID = docState.docID;
							bool success2 = false;
							try
							{
								waitQueue.Add(skipDocWriter);
								success2 = true;
							}
							finally
							{
								if (!success2)
								{
									state.isIdle = true;
									System.Threading.Monitor.PulseAll(this);
									Abort();
									// return false; // {{Aroush-2.9}} this 'return false' is move to outside finally
                                    doReturnFalse = true;
								}
							}

                            if (!doReturnFalse)   // {{Aroush-2.9}} added because of the above 'return false' removal
                            {
								state.isIdle = true;
								System.Threading.Monitor.PulseAll(this);
							
								// If this thread state had decided to flush, we
								// must clear it so another thread can flush
								if (state.doFlushAfter)
								{
									state.doFlushAfter = false;
									flushPending = false;
									System.Threading.Monitor.PulseAll(this);
								}
								
								// Immediately mark this document as deleted
								// since likely it was partially added.  This
								// keeps indexing as "all or none" (atomic) when
								// adding a document:
								AddDeleteDocID(state.docState.docID);
                            }
						}
					}
				}
			}

            if (doReturnFalse)  // {{Aroush-2.9}} see comment abouve
            {
                return false;
            }

			return state.doFlushAfter || TimeToFlushDeletes();
		}
Exemple #30
0
		/// <summary> Constructs a query parser.
		/// 
		/// </summary>
		/// <param name="matchVersion">Lucene version to match. See <a href="#version">above</a>)
		/// </param>
		/// <param name="f">the default field for query terms.
		/// </param>
		/// <param name="a">used to find terms in the query text.
		/// </param>
		public QueryParser(Version matchVersion, System.String f, Analyzer a):this(new FastCharStream(new System.IO.StringReader("")))
		{
			analyzer = a;
			field = f;
			if (matchVersion.OnOrAfter(Version.LUCENE_29))
			{
				enablePositionIncrements = true;
			}
			else
			{
				enablePositionIncrements = false;
			}
		}
Exemple #31
0
 public void Clear()
 {
     // don't hold onto doc nor analyzer, in case it is
     // largish:
     doc = null;
     analyzer = null;
 }
 public MultiFieldQueryParser(System.String[] fields, Analyzer analyzer) : this(Version.LUCENE_24, fields, analyzer)
 {
 }
Exemple #33
0
		public IndexWriter(System.IO.FileInfo path, Analyzer a)
		{
			InitBlock();
			Init(FSDirectory.GetDirectory(path), a, true, null, true, DEFAULT_MAX_FIELD_LENGTH, null, null);
		}
 public static Query Parse(System.String[] queries, System.String[] fields, Analyzer analyzer)
 {
     return(Parse(Version.LUCENE_24, queries, fields, analyzer));
 }
Exemple #35
0
		/// <summary> Adds a document to this index, using the provided analyzer instead of the
		/// one specific in the constructor.  If the document contains more than
		/// {@link #SetMaxFieldLength(int)} terms for a given field, the remainder are
		/// discarded.
		/// </summary>
		/// <seealso cref="IndexWriter.AddDocument(Document, Analyzer)">
		/// </seealso>
		/// <throws>  IllegalStateException if the index is closed </throws>
		/// <throws>  CorruptIndexException if the index is corrupt </throws>
		/// <throws>  LockObtainFailedException if another writer </throws>
		/// <summary>  has this index open (<code>write.lock</code> could not
		/// be obtained)
		/// </summary>
		/// <throws>  IOException if there is a low-level IO error </throws>
		public virtual void  AddDocument(Document doc, Analyzer docAnalyzer)
		{
			lock (directory)
			{
				AssureOpen();
				CreateIndexWriter();
				if (docAnalyzer != null)
					indexWriter.AddDocument(doc, docAnalyzer);
				else
					indexWriter.AddDocument(doc);
			}
		}
        /// <summary> Parses a query, searching on the fields specified. Use this if you need
        /// to specify certain fields as required, and others as prohibited.
        /// <p/>
        ///
        /// <pre>
        /// Usage:
        /// &lt;code&gt;
        /// String[] query = {&quot;query1&quot;, &quot;query2&quot;, &quot;query3&quot;};
        /// String[] fields = {&quot;filename&quot;, &quot;contents&quot;, &quot;description&quot;};
        /// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
        /// BooleanClause.Occur.MUST,
        /// BooleanClause.Occur.MUST_NOT};
        /// MultiFieldQueryParser.parse(query, fields, flags, analyzer);
        /// &lt;/code&gt;
        /// </pre>
        /// <p/>
        /// The code above would construct a query:
        ///
        /// <pre>
        /// &lt;code&gt;
        /// (filename:query1) +(contents:query2) -(description:query3)
        /// &lt;/code&gt;
        /// </pre>
        ///
        /// </summary>
        /// <param name="matchVersion">Lucene version to match; this is passed through to
        /// QueryParser.
        /// </param>
        /// <param name="queries">Queries string to parse
        /// </param>
        /// <param name="fields">Fields to search on
        /// </param>
        /// <param name="flags">Flags describing the fields
        /// </param>
        /// <param name="analyzer">Analyzer to use
        /// </param>
        /// <throws>  ParseException </throws>
        /// <summary>             if query parsing fails
        /// </summary>
        /// <throws>  IllegalArgumentException </throws>
        /// <summary>             if the length of the queries, fields, and flags array differ
        /// </summary>
        public static Query Parse(Version matchVersion, System.String[] queries, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
        {
            if (!(queries.Length == fields.Length && queries.Length == flags.Length))
            {
                throw new System.ArgumentException("queries, fields, and flags array have have different length");
            }
            BooleanQuery bQuery = new BooleanQuery();

            for (int i = 0; i < fields.Length; i++)
            {
                QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
                Query       q  = qp.Parse(queries[i]);
                if (q != null && (!(q is BooleanQuery) || ((BooleanQuery)q).GetClauses().Length > 0))
                {
                    bQuery.Add(q, flags[i]);
                }
            }
            return(bQuery);
        }
		/// <summary> Creates a MultiFieldQueryParser.
		/// 
		/// <p/>
		/// It will, when parse(String query) is called, construct a query like this
		/// (assuming the query consists of two terms and you specify the two fields
		/// <code>title</code> and <code>body</code>):
		/// <p/>
		/// 
		/// <code>
		/// (title:term1 body:term1) (title:term2 body:term2)
		/// </code>
		/// 
		/// <p/>
		/// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
		/// <p/>
		/// 
		/// <code>
		/// +(title:term1 body:term1) +(title:term2 body:term2)
		/// </code>
		/// 
		/// <p/>
		/// In other words, all the query's terms must appear, but it doesn't matter
		/// in what fields they appear.
		/// <p/>
		/// </summary>
		public MultiFieldQueryParser(Version matchVersion, System.String[] fields, Analyzer analyzer):base(matchVersion, null, analyzer)
		{
			this.fields = fields;
		}
Exemple #38
0
 /// <summary> Open an index with write access.
 ///
 /// </summary>
 /// <param name="directory">the index directory
 /// </param>
 /// <param name="analyzer">the analyzer to use for adding new documents
 /// </param>
 /// <param name="create"><code>true</code> to create the index or overwrite the existing one;
 /// <code>false</code> to append to the existing index
 /// </param>
 /// <throws>  CorruptIndexException if the index is corrupt </throws>
 /// <throws>  LockObtainFailedException if another writer </throws>
 /// <summary>  has this index open (<code>write.lock</code> could not
 /// be obtained)
 /// </summary>
 /// <throws>  IOException if there is a low-level IO error </throws>
 public IndexModifier(Directory directory, Analyzer analyzer, bool create)
 {
     InitBlock();
     Init(directory, analyzer, create);
 }
		public static Query Parse(System.String[] queries, System.String[] fields, Analyzer analyzer)
		{
			return Parse(Version.LUCENE_24, queries, fields, analyzer);
		}
		/// <summary> Creates a MultiFieldQueryParser. Allows passing of a map with term to
		/// Boost, and the boost to apply to each term.
		/// 
		/// <p/>
		/// It will, when parse(String query) is called, construct a query like this
		/// (assuming the query consists of two terms and you specify the two fields
		/// <code>title</code> and <code>body</code>):
		/// <p/>
		/// 
		/// <code>
		/// (title:term1 body:term1) (title:term2 body:term2)
		/// </code>
		/// 
		/// <p/>
		/// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
		/// <p/>
		/// 
		/// <code>
		/// +(title:term1 body:term1) +(title:term2 body:term2)
		/// </code>
		/// 
		/// <p/>
		/// When you pass a boost (title=>5 body=>10) you can get
		/// <p/>
		/// 
		/// <code>
		/// +(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)
		/// </code>
		/// 
		/// <p/>
		/// In other words, all the query's terms must appear, but it doesn't matter
		/// in what fields they appear.
		/// <p/>
		/// </summary>
		public MultiFieldQueryParser(Version matchVersion, System.String[] fields, Analyzer analyzer, System.Collections.IDictionary boosts):this(matchVersion, fields, analyzer)
		{
			this.boosts = boosts;
		}
Exemple #41
0
		/// <summary> Constructs an IndexWriter for the index in
		/// <code>d</code>, first creating it if it does not
		/// already exist.  Text will be analyzed with
		/// <code>a</code>.
		/// 
		/// <p/><b>NOTE</b>: autoCommit (see <a
		/// href="#autoCommit">above</a>) is set to false with this
		/// constructor.
		/// 
		/// </summary>
		/// <param name="d">the index directory
		/// </param>
		/// <param name="a">the analyzer to use
		/// </param>
		/// <param name="mfl">Maximum field length in number of terms/tokens: LIMITED, UNLIMITED, or user-specified
		/// via the MaxFieldLength constructor.
		/// </param>
		/// <throws>  CorruptIndexException if the index is corrupt </throws>
		/// <throws>  LockObtainFailedException if another writer </throws>
		/// <summary>  has this index open (<code>write.lock</code> could not
		/// be obtained)
		/// </summary>
		/// <throws>  IOException if the directory cannot be </throws>
		/// <summary>  read/written to or if there is any other low-level
		/// IO error
		/// </summary>
		public IndexWriter(Directory d, Analyzer a, MaxFieldLength mfl)
		{
			InitBlock();
			Init(d, a, false, null, false, mfl.GetLimit(), null, null);
		}
		public MultiFieldQueryParser(System.String[] fields, Analyzer analyzer):this(Version.LUCENE_24, fields, analyzer)
		{
		}
Exemple #43
0
		/// <summary> Initialize an IndexWriter.</summary>
		/// <throws>  CorruptIndexException if the index is corrupt </throws>
		/// <throws>  LockObtainFailedException if another writer </throws>
		/// <summary>  has this index open (<code>write.lock</code> could not
		/// be obtained)
		/// </summary>
		/// <throws>  IOException if there is a low-level IO error </throws>
		protected internal virtual void  Init(Directory directory, Analyzer analyzer, bool create)
		{
			this.directory = directory;
			lock (this.directory)
			{
				this.analyzer = analyzer;
				indexWriter = new IndexWriter(directory, analyzer, create, IndexWriter.MaxFieldLength.LIMITED);
				open = true;
			}
		}