# Lucene query serch on text column. Output should be two columns matching string and record\_id column

**URL:** <https://discuss.elastic.co/t/lucene-query-serch-on-text-column-output-should-be-two-columns-matching-string-and-record-id-column/14113>\
**Category:** Elasticsearch\
**Created:** [October 25, 2013, 10:24am UTC](https://discuss.elastic.co/t/lucene-query-serch-on-text-column-output-should-be-two-columns-matching-string-and-record-id-column/14113 "2013-10-25T10:24:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danesh](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@Danesh](https://discuss.elastic.co/u/Danesh)\
**Post date:** [October 25, 2013, 10:24am UTC](https://discuss.elastic.co/t/lucene-query-serch-on-text-column-output-should-be-two-columns-matching-string-and-record-id-column/14113/1 "2013-10-25T10:24:14Z")

</div>

Hi,

I have a description column on which i am applying search and with it i want to pass additional record\_id column which will help in joining the result set to other data sets. Please see the code below,  
input column is record\_id column where serch is not required and and input text is description column.  
What would be the simple way to return matching string and record\_id as output ??

RAMDirectory ramDirectory = new RAMDirectory();  
String inputColumn = (String) input.get(0);  
String inputText = (String) input.get(1);  
Document document = new Document();  
//You must specify the index to be analyzed for it to be "searchable"  
document.add(new Field(inputColumn, inputText, Store.NO,  
Index.ANALYZED, TermVector.NO));  
//Add the document to a searchable index  
config = new IndexWriterConfig(Version.LUCENE\_34, sAnalyzer);  
IndexWriter w = new IndexWriter(ramDirectory, config);  
//Out index only contains one posting that is searchable.  
w.addDocument(document);  
w.close();

```
IndexSearcher srcher = new IndexSearcher(
				IndexReader.open(ramDirectory));
		//For each rule, create the regex query and see if it applies
		for (Entry<String, String> ruleEntry : regexRules) {
			//Parse the string as a Lucene "query"
			Query query;
			try {
				query = queryParser.parse(ruleEntry.getValue());
				System.out.println("Value" +ruleEntry.getValue());
			} catch (ParseException e) {
				//Query could not be properly parsed. Something wrong with the Lucene query syntax
				System.err.println("The query is not well formed: " + ruleEntry.getValue() + "for the canonical name " + ruleEntry.getKey());
				e.printStackTrace();
				continue;
			//	System.out.println("Match found" +ruleEntry.getValue());
			}
			//Let the searcher see if it found a hit in the index
			TopDocs hits = srcher.search(query, 1);

			//Does our results contain at least one document [well there is only one
			//document anyway]; has that result been matched by our rule
			
			if (hits == null || hits.totalHits < 1)
				continue; // No value found; Proceed to apply the next rule
			
			else

                return ruleEntry.getKey();

```

Thank you  
Danesh

---

<div class="post-metadata">

**Author:** ![Danesh](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@Danesh](https://discuss.elastic.co/u/Danesh)\
**Post date:** [October 25, 2013, 10:26am UTC](https://discuss.elastic.co/t/lucene-query-serch-on-text-column-output-should-be-two-columns-matching-string-and-record-id-column/14113/2 "2013-10-25T10:26:06Z")

</div>

Pls help...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:10am UTC](https://discuss.elastic.co/t/lucene-query-serch-on-text-column-output-should-be-two-columns-matching-string-and-record-id-column/14113/3 "2017-07-06T02:10:39Z")

</div>

Closed on July 6, 2017, 2:10am UTC


