1 field: Autosuggest + Search - search

I've the following usecase:
I want to use a field for autosuggest and for fulltext-search with "q"-parameter
Now the problem is: When I want to do full-textsearch and choose "_textS" or "_textM" as type, then fulltextsearch works perfectly word-based.
But because of the tokenization which takes place for "*_textM" in solr, I get only 1 lowercase-piece of the whole word when doing autosuggest with "Eid/Suggest".
For example if I have indexed "This is a value" as "_textS" I only get "this" for autosuggest. What I need as autosuggest-value is "This is a value".
What's the best way to tackle this?

If you want to use same field for autosuggest as well as search. Then you can create a copy field of that field with different fieldType. For example content is the field which is you want to use for autosuggest-search.
Then you can use content as full text-search and create an another field content_suggest for suggestions which is copy field of content with different fieldType.
<field name="content" type="_textS" indexed="true" stored="true"/>
<field name="content_suggest" type="string" indexed="true" stored="true"/>
<copyField source="content" dest="content_suggest"/>

Ok. Why would you use "copyField" instead of "DocValues" for this usecase?

Related

Solr: top results when query (word/words) matches title, following when search matches descirption

I have a Java application that uses Solr and SolrJ API for search.
I have an object with title and description and some other fields that have been imported into solr.
I'm trying to make the top responses be when search words in the query match the title, when there are no more matches in the title, the following results should be those that have matches in their description.
I have title and description fields set in schema.xml
<field name="title" type="text_general" indexed="true" stored="false" multiValued="true"/>
<field name="description" type="text_general" indexed="true" stored="true" multiValued="true"/>
I have tried boosting them in solrconfig.xml but I'm not sure it will give me the desired results and have not given so far.
Any help would be much appreciated!

Search a multi-valued field with a self join

I have the following (simplified) solr schema:
<schema name="documents" version="1.1">
<uniqueKey>id</uniqueKey>
...
<fields>
<field
name="id"
type="string"
indexed="true"
stored="true"
required="true"/>
<field
name="documentReferences"
type="string"
indexed="true"
stored="false"
multiValued="true"
required="false"/>
</fields>
</schema>
The values which will be in this documentReferences field are all ids of other documents which are indexed in this solr core.
The search I want to accomplish (in english):
Documents who's id is not in any other document's documentReferences field
Is this possible? I don't have a problem indexing another field if it would help answer this question.
One of the Solution, I was thinking of was
Index the Id with the Document references itself, that would make sure if the document is not referenced by any other document the count would be one for sure
Search for All Documents Facet on the Document references and then filter the facets with count 1, which would be the list of the ids not refered by the other ids
Would have loved to use the facet maxcount param which would have limited the results for the search out of the box.

Complex query in Solr, is it possible?

Hey guys, I am new to Solr, and want to accomplish the following scenario (below), but not sure if Solr is capable of handling cases like that:
The problem very straight forward, I want to build a price comparison search. There are my rational DB tables:
t_company:
company_id
company_name
t_product:
product_id
product_price
t_company_product:
company_product_id
company_id
product_id
In Solr, I want to perform the following search - Get all companies that offer 1 or many of specific products for the lowest TOTAL price (so if you select screws, nails, and sheet rock, I want to give a total purchase lowest price).
When I set up my schema, I set the business as the main entity and product_ids and product_prices as two multivalued fields.
Can I query like that? How would I do sum?
Here is all my XML schema.xml and data-config.xml
<document name="companies">
<entity name="company" dataSource="dsCompany"
query="select
newid() as row_id,
company_id,
company_name
from
t_company WITH (NOLOCK)">
<field column="row_id" name="row_id" />
<field column="company_id" name="company_id" />
<field column="company_name" name="company_name" />
<entity name="products" query="select
company_product_id,
product_id,
price
from
t_company_product WITH (NOLOCK)
where
company_id='${company.company_id}'"
dataSource="dsCompany">
<field name="company_product_id" column="company_product_id" />
<field name="product_id" column="product_id" />
<field name="price" column="price" />
</entity>
</entity>
<fields>
<field name="row_id" type="string" indexed="true" stored="true" required="true"/>
<field name="company_id" type="integer" indexed="true" stored="true" required="true" />
<field name="company_name" type="text" indexed="true" stored="true"/>
<field name="service_id" type="integer" indexed="true" stored="true" required="true" />
<field name="price" type="tfloat" indexed="true" stored="true" required="true" />
</fields>
Any feedback will be greatly appreciated!!!
You can use a function query to sort the results by a sum, see here.
In my last project we used a nightly build of 4.0 and it is working fine. It contains so much more functionality than 1.4 that is worth the small risk you may take by using a non released version.
Update:
To use the sum you could try to do add a dynamic field per each product price (I don't know how to use the sum with multivalued fields or if it is possible).
Add to data-config
<field name="price_${products.product_id}" column="price" />
Add to schema.xml
<dynamicField name="price_*" type="decimal" indexed="false" stored="true" />
and if I understand it correctly you should be able to use a query like:
q=:&sort=sum(price_"id for nails",price_"id for screws",price_"id for ...") asc
In 1.4.1 probably, in current trunk (4.0) no or at least not easily.
In solr 1.4 there is field collapsing that can perform aggregates over the records returned. In trunk solr 4.0 this has turned into a grouping option that can perform only min / max type queries (as far as I'm aware).
The documentation can be found here:
http://wiki.apache.org/solr/FieldCollapsing
Remember you'll have to expand out the relationships ( consider it as 1 big denormalised view over the tables involved ).
Solr is not intended to replace a relational database. If you would still like to index relational content then they need to be denormalized hence would contain redundant data. So the count of # of results will be off for most of the queries, for example a search for just the company name will yield a higher total number of results than expected. However with field collapsing you can get away from it. However if you use faceting then eliminating duplicates from there is not possible afaik.
If you form a single schema with all the data that you had mentioned then you could perform the relational queries to a certain extent. Google "solr issue 2272" to get the details. It is currently possible only within a single schema.
Performing a summation operation within a search engine is not possible at this time i believe. i might be wrong and if someone knows a way to do it, i will be very interested also.
I think you might be asking about how to customize scoring. Here's an example in lucene.
http://sujitpal.blogspot.com/2010/10/custom-scoring-with-lucene-payloads.html
From LucidImagination
http://www.lucidimagination.com/blog/2009/08/05/getting-started-with-payloads/

Sharepoint 2007: Create a multi-line text custom property for a custom field type?

I'm trying to extend the built-in Choice field type to include another piece of data: a correct answer. With this, users would be able to create their own tests directly within Sharepoint instead of having to use InfoPath or some other convoluted solution. I was hoping to just inherit the existing SPFieldChoice type and add one more custom property to hold an integer representing the correct answer from the choices entered.
I've got a FieldTestQuestion class that inherits from SPFieldChoice along with a pretty basic TestQuestionFieldControl class inheriting from RadioButtonChoiceField. My fldtypes_TestQuestionField.xml file:
<FieldTypes>
<FieldType>
<Field Name="TypeName">TestQuestion</Field>
<Field Name="ParentType">Choice</Field>
<Field Name="TypeDisplayName">Test Question (Multiple choice)</Field>
<Field Name="TypeShortDescription">Test Question (Multiple choice)</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowInColumnTemplateCreate">TRUE</Field>
<Field Name="FieldTypeClass">MyCustomFieldTypes.FieldTestQuestion,MyCustomFieldTypes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=****</Field>
<PropertySchema>
<Fields>
<Field Name="CorrectAnswer" DisplayName="Correct answer (line number)" Type="Integer">
<Default></Default>
</Field>
</Fields>
</PropertySchema>
</FieldType>
</FieldTypes>
Unfortunately, this is what renders when I try adding a column of this type:
(source: mudman.us)
No option to add the choices as with the Choice field type:
(source: mudman.us)
What do I need to put in my fldTypes_.xml to tell Sharepoint to either (a) use the existing custom properties for the Choice column and ADD the extra property I specified or (b) specifically define a multi-line text custom property?
It would appear the Choice input box is being created specifically for SPFieldChoice columns; one of many un-inheritable features. This means that you're unlikely to be able to persuade SharePoint to reproduce it for your custom field type.
My advice would be to go for option b), and create it yourself. I believe adding this to the <fields> element will do the trick:
<Field Name="ChoiceFix" DisplayName="Type each choice on a separate line:" Type="Note" />
Be warned that I haven't tested this solution reliability, and you may have to go down the spiky and unpleasant route of making your own Field Editor Control.

CAML cannot reference Custom Properties in custom fields

I am trying to create a custom field type in SharePoint.
My custom field type has a custom property called CustomProperty.
<FieldTypes>
<FieldType>
<Field Name="TypeName">CustomField</Field>
<Field Name="InternalType">CustomField</Field>
..............................
..............................
<PropertySchema>
<Fields>
<Field Name="CustomProperty" DisplayName="CustomProperty" Type="Text" Hidden="TRUE" />
</Fields>
<RenderPattern Name="DisplayPattern">
<Property Select="CustomProperty" />
</RenderPattern>
</FieldType>
</FieldTypes>
I am trying to render the value of this custom property in the DisplayPattern.
But it looks like the CAML is not able to reference the custom properties.
I am not getting any value for the CustomValue property even though it is set correctly.
Any idea how to refer custom properties in CAML?
Unfortunately there is no straightforward way of achieving this, from what I've seen.
Your best option is to look at using this.GetCustomProperty("CustomProperty") within the overrided GetFieldValue function (or GetFieldValueAsHtml for a Note field).
The value string passed into the GetFieldValue function is the output from your CAML, so you can append to it and pass it on out.
Here is a sample:
http://blogs.msdn.com/toddca/archive/2009/01/23/customizing-the-rendering-of-a-custom-spfield.aspx
I haven’t tried it myself, and I have no idea if changing the SchemaXml could cause any unexpected problems.

Resources